home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 501-525 / disk_503 / pcq / pcq12a.lzh / Examples / RexxHost.p < prev    next >
Text File  |  1990-07-19  |  2KB  |  78 lines

  1. Program RexxHost;
  2.  
  3. { This program runs an ARexx command called "RexxHost.RXH",
  4.   waits for its commands (and tells you about them when they
  5.   come), and quits whenever the ARexx program is finished.  }
  6.  
  7. {$I "Include:Exec/Libraries.i"}
  8. {$I "Include:Exec/Ports.i"}
  9. {$I "Include:Rexx/ARexxStrings.i"}
  10. {$I "Include:Rexx/RexxIO.i"}
  11. {$I "Include:Rexx/Storage.i"}
  12. {$I "Include:Exec/Interrupts.i"}
  13.  
  14. VAR
  15.     MyPort: MsgPortPtr;
  16.  
  17. Procedure Demo;
  18. var
  19.     rmptr    : RexxMsgPtr;
  20.     MyCommand    : RexxMsgPtr;
  21.     RexxPort    : MsgPortPtr;
  22.     Token,
  23.     Scan    : String;
  24.     Quote    : Char;
  25.     Len        : Integer;
  26. begin
  27.     RexxSysBase := OpenLibrary("rexxsyslib.library", 0);
  28.     if RexxSysBase <> nil then begin
  29.     New(MyPort);    { Allocate memory }
  30.     if InitPort(MyPort, "MyPort") <> -1 then begin
  31.         AddPort(MyPort);
  32.         MyCommand := CreateRexxMsg(MyPort, "RXH", "MyPort");
  33.         MyCommand^.rm_Args[0] := CreateArgString("RexxHost.RXH", 12);
  34.         MyCommand^.rm_Action := RXCOMM;
  35.         Forbid;
  36.         RexxPort := FindPort("REXX");
  37.         if RexxPort = nil then begin
  38.         Permit;
  39.         Writeln('Could not find the ARexx port');
  40.         ClearRexxMsg(MyCommand, 16);
  41.         DeleteRexxMsg(MyCommand);
  42.         RemPort(MyPort);
  43.         FreePort(MyPort);
  44.         CloseLibrary(RexxSysBase);
  45.         Exit(20);
  46.         end;
  47.         PutMsg(RexxPort, MessagePtr(MyCommand));
  48.         Permit;
  49.         repeat
  50.         rmptr := RexxMsgPtr(WaitPort(MyPort));
  51.         rmptr := RexxMsgPtr(GetMsg(MyPort));
  52.         if rmptr <> MyCommand then begin
  53.             StcToken(rmptr^.rm_Args[0], Quote, Len, Scan, Token);
  54.             writeln(Scan);
  55.             rmptr^.rm_Result1 := 0;
  56.             rmptr^.rm_Result2 := 0;
  57.             ReplyMsg(MessagePtr(rmptr));
  58.         end else begin
  59.             writeln('received the reply');
  60.             writeln('return code 1 was ', MyCommand^.rm_Result1);
  61.             writeln('return code 2 was ', MyCommand^.rm_Result2);
  62.         end;
  63.         until rmptr = MyCommand;
  64.         ClearRexxMsg(MyCommand, 16);
  65.         DeleteRexxMsg(MyCommand);
  66.         RemPort(MyPort);
  67.         FreePort(MyPort);
  68.     end else
  69.         writeln('Could not initialize the port.');
  70.     CloseLibrary(RexxSysBase);
  71.     end else
  72.     Writeln('Could not open the ARexx library.');
  73. end;
  74.  
  75. begin
  76.     Demo;
  77. end.
  78.